<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        div{
            overflow: hidden;
            position: relative;
            width: 400px;
            height: 400px;
            margin: 100px auto;
            border: 5px solid #000000;
        }
        ul {

            width: 400%;
            position: absolute;
        }
        li {
            float: left;
            width: 400px;
            height: 400px;
            list-style: none;
            font: 50px/400px "微软雅黑";
            text-align: center;
            color: #fff;
        }
        li:nth-child(1){
            background-color: red;
        }
        li:nth-child(2){
            background-color: green;
        }
        li:nth-child(3){
            background-color: blue;
        }
        li:nth-child(4){
            background-color: red;
        }
    </style>
</head>
<body>
<div id='box'>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>1</li>
    </ul>
</div>
<script>
    var box = document.getElementById("box");
    var ul = box.firstElementChild;
    //盒子的距离 =  当前的距离 + 步长
    var timerId = null;
   function move(){
       timerId = setInterval(function(){
           if(ul.offsetLeft > -1200) {
               ul.style.left = ul.offsetLeft + -5 + "px";
           } else {
               ul.style.left = "0px";
           }
       },15)
   }
    move();
    box.onmouseover= function(){
        clearInterval(timerId);
    }
    box.onmouseout = function(){
        move();
    }
</script>
</body>
</html>